#include <windows.h>
#include <stdio.h>

typedef struct charobj_tag{
    char ch;
    COORD curPos;
    COORD prePos;
    COORD dstPos;
    
}charobj;

void updateChars(charobj chars[],int n)
{
    int i;
    COORD pos;
    HANDLE stdo=GetStdHandle(STD_OUTPUT_HANDLE);
        
    for(i=0;i<n;++i){
        SetConsoleCursorPosition(stdo,chars[i].prePos);
        putchar(' ');
        

        SetConsoleCursorPosition(stdo,chars[i].curPos);
        putchar(chars[i].ch);
    }    
        
    
}
              
    
void droptext(char str[])
{

#define TEXTTOP 10
#define TEXTLEFT 20
#define FRAMES  25
#define DUNPLICATE 5
#define LIMITER 0

    int i,j,charx,chary;
    int charobj_count;
    
    
    charobj_count=strlen(str)*DUNPLICATE;
    
    charobj* chars=(charobj*)malloc(sizeof(charobj)*charobj_count);
    
    for(i=0;i<strlen(str);++i){
        for(j=0;j<DUNPLICATE;++j){
            chars[i*DUNPLICATE+j].ch=str[i];
            chars[i*DUNPLICATE+j].prePos.X=0;
            chars[i*DUNPLICATE+j].prePos.Y=0;
            chars[i*DUNPLICATE+j].curPos.X=rand()%80;
            chars[i*DUNPLICATE+j].curPos.Y=rand()%25;
            
            chars[i*DUNPLICATE+j].dstPos.X=TEXTLEFT+i;
            chars[i*DUNPLICATE+j].dstPos.Y=TEXTTOP;
        }                
        
    }
      
    
    for(j=0;j<FRAMES;++j){
        for(i=0;i<charobj_count;++i){
            charx = chars[i].dstPos.X - chars[i].curPos.X;
            chary = chars[i].dstPos.Y - chars[i].curPos.Y;
    
            charx/= (FRAMES - j);
            chary/= (FRAMES - j);
        
            /*l1(i).ForeColor = RGB(255 - j, 255 - j, 255 - j)*/

            chars[i].prePos.X=chars[i].curPos.X;
            chars[i].prePos.Y=chars[i].curPos.Y;
            
            chars[i].curPos.X += charx;
            chars[i].curPos.Y += chary;
        }
        
        updateChars(chars,charobj_count);
        
        if(LIMITER)Sleep(LIMITER);
    }    

/*For j = 1 To 128
    For i = 1 To Len(str)

        l1(i).ForeColor = RGB(j * 2, j * 2, j * 2)
        DoEvents
    Next
    DoEvents
    If Limiter > 0 Then Sleep Limiter
Next

For i = 1 To Len(str)
    Unload l1(i)
   
    
Next
running = False
End Sub*/
    free(chars);
}
    
